package com.bm.controller;

import com.bm.Do.Repair.RepairMyListDo;
import com.bm.Result.CodeEnum;
import com.bm.Result.Result;
import com.bm.Vo.Repair.RepairAllotVo;
import com.bm.Vo.Repair.RepairDetailVo;
import com.bm.Vo.Repair.RepairListVo;
import com.bm.Vo.Repair.RepairMyDetailVo;
import com.bm.model.EjyyRepair;
import com.bm.query.Common.DetailQuery;
import com.bm.query.Repair.*;
import com.bm.service.EjyyRepairService;
import com.bm.util.DateUtils;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 86134
 * @version 1.0
 * @description TODO
 * @date 2024/3/7 20:22
 */
@RestController
@Api(tags = "维修维护相关接口")
public class RepairController {

    @Autowired
    private EjyyRepairService ejyyRepairService;

    @PostMapping("/repair/list")
    @ApiOperation(value = "查看所有维修信息")
    public Result RepairList(@RequestBody RepairListQuery repairListQuery) {
        PageInfo<RepairListVo> repairListVo = ejyyRepairService.repairList(repairListQuery);
        return Result.OK(repairListVo);
    }

    @PostMapping("/repair/create")
    @ApiOperation(value = "创建工单api")
    public Result RepairCreate(@RequestBody EjyyRepair repair) {
        boolean flag = ejyyRepairService.createRepair(repair);
        return flag ? Result.OK() : Result.FAIL();
    }

    @PostMapping("/repair/detail")
    @ApiOperation(value = "工单详情api")
    public Result RepairDetail(@RequestBody DetailQuery detailQuery) {
        RepairDetailVo repairDetailVo = ejyyRepairService.DetailRepair(detailQuery);
        return repairDetailVo == null ? Result.FAIL(CodeEnum.QUERY_ILLEFAL) : Result.OK(repairDetailVo);
    }

    @PostMapping("/repair/allot")
    @ApiOperation(value = "接派员工单api")
    public Result RepairAllot(@RequestBody RepairAllotQuery repairAllotQuery) {
        RepairAllotVo ejyyRepair = ejyyRepairService.repairAllot(repairAllotQuery);
        return ejyyRepair == null ? Result.FAIL(CodeEnum.REPAIR_QUERY_ILLEFAL) : Result.OK(ejyyRepair);
    }

    @PostMapping("/repair/confirm")
    @ApiOperation(value = "确认维修api")
    public Result RepairConfirm(@RequestBody RepairConfirmQuery repairConfirmQuery){
        Boolean flag = ejyyRepairService.repairConfirm(repairConfirmQuery);
        return flag ? Result.OK(DateUtils.dateConversion()) : Result.FAIL(CodeEnum.QUERY_ILLEFAL);
    }

    @PostMapping("/repair/finish")
    @ApiOperation(value = "查看维修完成api")
    public Result RepairFinish(@RequestBody RepairFinishQuery repairFinishQuery){
        Boolean flag = ejyyRepairService.repairFinish(repairFinishQuery);
        return flag ? Result.OK(DateUtils.dateConversion()) : Result.FAIL(CodeEnum.QUERY_ILLEFAL);
    }

    @PostMapping("/repair/merge_option")
    @ApiOperation(value = "合并维修数据api")
    public Result repairMergeOption(@RequestBody DetailQuery detailQuery){
        List<EjyyRepair> list = ejyyRepairService.repairMergeOption(detailQuery);
        return list != null ? Result.OK(list) : Result.FAIL(CodeEnum.QUERY_ILLEFAL);
    }

    @PostMapping("/repair/merge")
    @ApiOperation(value = "查看合并维修数据api")
    public Result RepairMerge(@RequestBody RepairMergeQuery repairMergeQuery){
        Long mergeId = ejyyRepairService.repairMerge(repairMergeQuery);
        return mergeId != null ? Result.OK(mergeId) : Result.FAIL(CodeEnum.QUERY_ILLEFAL);
    }

    @PostMapping("/repair/my_detail")
    @ApiOperation(value = "查看维修详情信息api")
    public Result RepairMyDetail(@RequestBody DetailQuery detailQuery){
        RepairMyDetailVo repairMyDetailVo = ejyyRepairService.repairMyDetail(detailQuery);
        return repairMyDetailVo != null ? Result.OK(repairMyDetailVo) : Result.FAIL(CodeEnum.QUERY_ILLEFAL);
    }

    @PostMapping("/repair/my_list")
    @ApiOperation(value = "查看我的全部维修数据api")
    public Result RepairMyList(@RequestBody RepairMyListQuery repairMyListQuery){
        PageInfo<RepairMyListDo> pageInfo = ejyyRepairService.repairMyList(repairMyListQuery);
        return Result.OK(pageInfo);
    }



}
